﻿using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Shared.Service.DataScopes.UserScopes
{
    /// <summary>
    /// 用户 的数据范围 作用在用户维度
    /// </summary>
    public class UserScopeProvider : DataScopeProvider,IUserScopeProvider
    {
        /// <summary>
        /// 用户
        /// </summary>
        public const string ProviderName = "U";

        /// <summary>
        /// Name => ProviderName
        /// </summary>
        public override string Name => ProviderName;
        
        public UserScopeProvider(IDataScopeStore policyScopeStore) : base(policyScopeStore)
        {

        }

        public async Task<List<UserDataScope>> GetScopesAsync(string userId)
        {
            var scopes = await this.DataScopeStore.GetDataScopesAsync(userId, ProviderName, userId);
            return scopes.Select(s => new UserDataScope(s)).ToList();
        }
    }
}
